package com.ruoyi.service.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.Discount;
import com.ruoyi.service.service.IDiscountService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.ExcelUtil;

/**
 * 优惠电费 信息操作处理
 * 
 * @author john
 * @date 2019-01-04
 */
@Controller
@RequestMapping("/service/discount")
public class DiscountController extends BaseController
{
    private String prefix = "service/discount";
	
	@Autowired
	private IDiscountService discountService;
	
	@GetMapping()
	public String discount()
	{
	    return prefix + "/discount";
	}
	
	/**
	 * 查询优惠电费列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Discount discount)
	{
		startPage();
        List<Discount> list = discountService.selectDiscountList(discount);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出优惠电费列表
	 */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Discount discount)
    {
    	List<Discount> list = discountService.selectDiscountList(discount);
        ExcelUtil<Discount> util = new ExcelUtil<Discount>(Discount.class);
        return util.exportExcel(list, "discount");
    }
	
	/**
	 * 新增优惠电费
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存优惠电费
	 */
	@Log(title = "优惠电费", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Discount discount)
	{		
		return toAjax(discountService.insertDiscount(discount));
	}

	/**
	 * 修改优惠电费
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Discount discount = discountService.selectDiscountById(id);
		mmap.put("discount", discount);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存优惠电费
	 */
	@Log(title = "优惠电费", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Discount discount)
	{		
		return toAjax(discountService.updateDiscount(discount));
	}
	
	/**
	 * 删除优惠电费
	 */
	@Log(title = "优惠电费", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(discountService.deleteDiscountByIds(ids));
	}
	
}
